<template>
    <ContentWrap>
        <div class="files-hd">
          <h4>基本属性</h4>
      </div>
      <table style="width: 100%;" class="gridtable spanFont">
          <tr>
              <th style="width: 15%;">屋面防水层</th>
              <td style="width: 30%;">
                  <el-radio-group >
                      <el-radio value="1">卷材防水</el-radio>
                      <el-radio value="2">刚性防水</el-radio>
                      <el-radio value="3">涂膜防水</el-radio>
                      <el-radio value="4">其他<el-input class="no-border-input underline-input" style="width: 100%;" /></el-radio>
                  </el-radio-group>
              </td>
              <th style="width: 15%;">底座固定形式</th>
              <td style="width: 30%;">
                  <el-radio-group >
                      <el-radio value="1">混凝土基墩</el-radio>
                      <el-radio value="2">混凝土基墩</el-radio>
                      <el-radio value="3">其他<el-input class="no-border-input underline-input" style="width: 100%;" /></el-radio>
                  </el-radio-group>
              </td>   
          </tr>
          <tr>
              <th>屋面板类型</th>
              <td>
                  <el-radio-group >
                      <el-radio value="1" >现浇板</el-radio>
                      <el-radio value="2" >现浇板 
                          <span>（厚度:</span><el-input class="no-border-input underline-input" style="width: 30%;" /> 
                          <span>mm）</span>
                      </el-radio>
                      <el-radio value="3">其他<el-input class="no-border-input underline-input" style="width: 100%;" /></el-radio>
                  </el-radio-group>
              </td>
              <th></th>
              <td></td>
          </tr> 
        </table>
    </ContentWrap>
</template>
<script lang="ts" setup>
import { useTagsViewStore } from '@/store/modules/tagsView'
import { OperateLogVO } from '@/api/system/operatelog'
import * as ProductApi from '@/api/crm/product'
import { BizTypeEnum } from '@/api/crm/permission'
import { getOperateLogPage } from '@/api/crm/operateLog'

defineOptions({ name: 'CrmProductAdd' })

const route = useRoute()
const message = useMessage()
const id = route.params.id // 编号
const type = route.params.type // 类型
const loading = ref(true) // 加载中
const formData = ref({
  id: undefined,
  name: undefined,
  no: undefined,
  unit: undefined,
  price: Number(undefined),
  status: undefined,
  categoryId: undefined,
  description: undefined,
  ownerUserId: -1
})

/** 获取详情 */
const getProductData = async (id: number) => {
  loading.value = true
  try {
    formData.value = await ProductApi.getProduct(id)
    await getOperateLog(id)
  } finally {
    loading.value = false
  }
}

/** 获取操作日志 */
const logList = ref<OperateLogVO[]>([]) // 操作日志列表
const getOperateLog = async (productId: number) => {
  if (!productId) {
    return
  }
  const data = await getOperateLogPage({
    bizType: BizTypeEnum.CRM_PRODUCT,
    bizId: productId
  })
  logList.value = data.list
}

/** 初始化 */
const { delView } = useTagsViewStore() // 视图操作
const { currentRoute } = useRouter() // 路由
onMounted(async () => {
  if (id) {
    await getProductData(id);
  }else{
    resetForm();
  }
})

/** 重置表单 */
const resetForm = () => {
  formData.value = {
    id: undefined,
    name: undefined,
    no: undefined,
    unit: undefined,
    price: Number(undefined),
    status: undefined,
    categoryId: undefined,
    description: undefined,
    ownerUserId: -1
  }

}
</script>
